package com.chinasofti.java8.demo04;

import org.junit.Test;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

public class TestStream3 {
//integer[]数组 = [1,2,3,4,5]返回一个平方的结构
//[1,4,9,16,25] 使用stream流实现

        @Test
        public  void test1(){
            Integer [] nums =  new Integer[]{1,2,3,4,5};
            Arrays.stream(nums).map((x)->x*x).forEach(System.out::println);
            System.out.println(nums);
    }
    List<Employee> emps = Arrays.asList(
            new Employee(101, "张三", 18, 9999.99)
            , new Employee(102, "李四", 59, 6666.66)
            , new Employee(103, "王五", 28, 3333.33)
            , new Employee(104, "赵六", 8, 7777.7)
            , new Employee(105, "田七", 38, 5555.55)
            , new Employee(105, "田七", 38, 5555.55)
    );
    @Test
    public  void test2(){
        Optional<Integer> count = emps.stream().map((e) -> 1).reduce(Integer::sum);
        System.out.println(count.get() );
    }

}